package com.boc.langxiang.presenter.shop;

import android.view.MenuItem;

import com.boc.langxiang.contract.shop.SpecialDetailContract;
import com.boc.langxiang.entity.request.SpecialTopicRequest;
import com.boc.langxiang.entity.response.BaseResponse;
import com.boc.langxiang.entity.response.SpecialLikeContent;
import com.boc.langxiang.entity.response.SpecialTopicDetailContent;
import com.boc.langxiang.entity.response.SpecialTopicShareContent;
import com.boc.langxiang.manager.UserInfoManager;
import com.boc.langxiang.net.HandleErrorSubscriber;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Li Guoxi on 2016/7/13.
 */
public class SpecialTopicDetailPresenter extends SuperPresenter implements SpecialDetailContract.Presenter {
    private SpecialDetailContract.View mView;

    public SpecialTopicDetailPresenter(SpecialDetailContract.View view) {
        super(view);
        this.mView = view;
    }

    @Override
    public void getDetail(String id) {
        mView.showLoading();
        mService.specialDetail(new SpecialTopicRequest(id).params())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<SpecialTopicDetailContent>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<SpecialTopicDetailContent> response) {
                        mView.onGetDetailSuccess(response.getContent());
                    }
                });
    }

    @Override
    public void like(String id, final MenuItem item) {
//        mView.showLoading();
        mService.specialLike(id, UserInfoManager.getInstance().getToken())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<SpecialLikeContent>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<SpecialLikeContent> response) {
                        mView.onLikeSuccess(response.getContent(), item);
                    }
                });
    }

    @Override
    public void getShareData(String id) {
//        mView.showLoading();
        mService.specialShareData(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())
                .subscribe(new HandleErrorSubscriber<BaseResponse<SpecialTopicShareContent>>(mView) {
                    @Override
                    public void onSuccess(BaseResponse<SpecialTopicShareContent> response) {
                        mView.onGetShareDataSuccess(response.getContent());
                    }
                });
    }
}
